/**
 * 双色球中奖等级判断类
 */
public class Text1 {

    /**
     * 判断中奖等级
     * @param userRedBalls 用户选择的红球号码
     * @param userBlueBall 用户选择的蓝球号码
     * @param drawRedBalls 开奖的红球号码
     * @param drawBlueBall 开奖的蓝球号码
     * @return 中奖等级，0表示未中奖
     */
    public int checkPrizeLevel(int[] userRedBalls, int userBlueBall, int[] drawRedBalls, int drawBlueBall) {
        int redMatchCount = countRedBallMatches(userRedBalls, drawRedBalls);
        boolean blueMatched = (userBlueBall == drawBlueBall);

        if (redMatchCount == 6 && blueMatched) return 1;    // 一等奖
        if (redMatchCount == 6 && !blueMatched) return 2;   // 二等奖
        if (redMatchCount == 5 && blueMatched) return 3;    // 三等奖
        if (redMatchCount == 5 || (redMatchCount == 4 && blueMatched)) return 4; // 四等奖
        if (redMatchCount == 4 || (redMatchCount == 3 && blueMatched)) return 5; // 五等奖
        if (blueMatched) return 6;                          // 六等奖
        return 0;                                           // 未中奖
    }

    /**
     * 计算红球匹配数量
     * @param userRedBalls 用户选择的红球号码
     * @param drawRedBalls 开奖的红球号码
     * @return 匹配的红球数量
     */
    private int countRedBallMatches(int[] userRedBalls, int[] drawRedBalls) {
        int count = 0;
        for (int userBall : userRedBalls) {
            for (int drawBall : drawRedBalls) {
                if (userBall == drawBall) {
                    count++;
                    break;
                }
            }
        }
        return count;
    }

    /**
     * 将中奖等级转换为奖项名称
     * @param level 中奖等级
     * @return 奖项名称
     */
    public String getPrizeName(int level) {
        switch (level) {
            case 1: return "一等奖";
            case 2: return "二等奖";
            case 3: return "三等奖";
            case 4: return "四等奖";
            case 5: return "五等奖";
            case 6: return "六等奖";
            default: return "未中奖";
        }
    }
}